<%@ Page Language="C#" Inherits="IBuyAdventure.PageBase" src="components/stdpage.cs" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Register TagPrefix="IBA" TagName="Header" Src="UserControl\Header.ascx" %>
<%@ Register TagPrefix="IBA" TagName="Categories" Src="UserControl\Categories.ascx" %>

<HTML>
  <HEAD>
    <TITLE>IBuyAdventure Catalog</TITLE>
  </HEAD>
 
<script language="C#" runat="server">
	void Page_Load(Object sender, EventArgs e)
	{
		// Store Return Url in Page State 
		if (Request.QueryString["ReturnUrl"] != null) 
		{
        ReturnUrl.Value = Request.QueryString["ReturnUrl"];
		((HyperLink)RegisterUser).NavigateUrl = "Register.aspx?ReturnUrl=" + ReturnUrl.Value;
		}
	}

	void LoginBtn_Click(Object sender, EventArgs e) 
	{
		IBuyAdventure.UsersDB users = new IBuyAdventure.UsersDB(getConnStr());    
        IBuyAdventure.CartDB cart = new IBuyAdventure.CartDB(getConnStr());  
        
        if (users.ValidateLogin(UserName.Text, Password.Text)) {
        
          // Migrate any temporary shopping cart items to logged-in username
          cart.MigrateShoppingCartItems(Session["AnonUID"].ToString(), UserName.Text);
          // Set Client Authentication Cookie
          FormsAuthentication.RedirectFromLoginPage(UserName.Text, Persist.Checked); 
          
        }
        else {
          Message.Text = "Login failed, please check your details and try again.";
        }
      }

  </script>

  <BODY BACKGROUND="images/back_sub.gif"> 

    <form method=post action="Login.aspx" runat="server">

      <FONT FACE="Verdana, Arial, Helvetica" SIZE=2>

        <TABLE BORDER=0>

          <tr>
            <td colspan=5>      
              <IBA:Header id="Header" runat="server"/>
            </td>
          </tr>  

          <!--Begin Navigational Buttons-->

          <TR>
            <TD ROWSPAN=5 ALIGN=LEFT VALIGN=TOP>

              <IBA:Categories id="Categories" runat="server"/>
              
              
            </TD>
            <TD valign=top>

              <center>
              <br>
              
              <input type=hidden value="/IBuyAdventure/default.aspx" id="ReturnUrl" runat="server">
              <P><font size=2>You have tried to access a secure section of the site, please login or register:<BR><BR>                          
              <TABLE CELLPADDING=5 COLSPAN=2>
                <TR>
                  <TD WIDTH=310 BGCOLOR="#800000">
                    <FONT COLOR="#FFFFFF" STYLE="Verdana, Arial, Helvetica" SIZE=2><b>Login</b></FONT>
                  </TD>
                </TR>
                <TR>
                  <TD BGCOLOR="f7efde" VALIGN=TOP>
                    
                      <table>
                        <tr>
                          <td width=100><FONT SIZE=2>Email Address: </FONT></td>
                          <td><asp:textbox id="UserName" width=160 runat="server"/></td>
                        </tr>
                        <tr>
                          <td><FONT SIZE=2>Password: </FONT></td>
                          <td><asp:textbox id="Password" TextMode="Password" width=160 runat="server"/></td>
                        </tr>
                        <tr>
                          <td></td>
                          <td><asp:checkbox id="Persist" runat="server"/> <FONT SIZE=2>Remember Password</font></td>
                        </tr>                        
                        <tr>
                          <td colspan=2 align=right>
                            <asp:button Text=" Login " OnClick="LoginBtn_Click" runat="server"/>
                          </td>
                        </tr>
                      </table>
                      
                    </FONT>
                  </TD>
                </TR>
              </TABLE>
                                 
              <br>
              
              <font size=2>
                <asp:HyperLink NavigateUrl="Register.aspx" id="RegisterUser" runat="server">Click Here to Register New Account </asp:hyperlink>
              </font>
              
              <br><br>
              
              <font size=2 color=red>     
                <b>
                  <asp:label id="Message" runat="server"/>
                </b>
              </font>              
              
              </center>
              
            </TD>
          </TR>
        </TABLE>
      </FONT>
    </form>
  </BODY>
</HTML>

     